﻿// ReSharper disable CheckNamespace

using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Routing;

namespace System.Web.Mvc
// ReSharper restore CheckNamespace
{
    public static class FckTextBoxExt
    {
        public static string FckTextBox(this HtmlHelper html, string name)
        {
            return FckTextBox(html, name, null);
        }

        public static string FckTextBox(this HtmlHelper html, string name, object value)
        {
            return FckTextBox(html, name, value.ToString());
        }

        public static string FckTextBox(this HtmlHelper html, string name, string value)
        {
            return FckTextBox(html, name, value, "600px", "350px");
        }

        public static string FckTextBox(this HtmlHelper html, string name, object value, string width, string height)
        {
            ModelState modelState;
            if (html.ViewData.ModelState.TryGetValue(name, out modelState))
            {
                value= modelState.Value.ConvertTo(typeof(string), null);
            }
            
            return string.Format(@"<textarea name=""{0}"" id=""{0}"">{1}</textarea>
                <script type=""text/javascript"">
                    CKEDITOR.replace('{0}',{{width:'{2}',height:'{3}'}});
                </script>", name, value, width, height);
        }
    }
}
